//var $j = jQuery.noConflict();
/* uncomment this block if there are some conflicts with other js library/framework */
(function ($) {

MyPage = {
    element: {
        btnSelectAllServices: null
		, btnReset: null
		, frmSearch: null
		, btnSearchVoluntaryOrganisation: null
		, btnSearchPrivateOrganisation: null
		, btnSearchGovernmentOrganisation: null
		, btnSearchAllOrganisation: null
    },

    builder: {},

    application: {
		resetForm: function ( ){
			MyPage.element.frmSearch.find('input:checkbox[name="chkServiceType[]"]').attr('checked' , false ).attr('selected' , false );
			MyPage.element.frmSearch.each (function() {this.reset();});
			//MyPage.element.frmSearch.find('checkbox[name="radSearchType"]').attr('checked' , false ).attr('selected' , false );
		}
		
    },

    prepareElement: function () {
        this.element = {
            btnSelectAllServices: $("#btnSelectAllServices")
			, btnReset: $("#btnReset")
			, frmSearch: $("#frmSearch")
			, btnSearchVoluntaryOrganisation: $("#btnSearchVoluntaryOrganisation")
			, btnSearchPrivateOrganisation: $("#btnSearchPrivateOrganisation")
			, btnSearchGovernmentOrganisation: $("#btnSearchGovernmentOrganisation")
			, btnSearchAllOrganisation: $("#btnSearchAllOrganisation")
        };
    },

    prepareView: function () {
        this.element.btnSelectAllServices.button();
		this.element.btnReset.button();
    },

    eventBinding: function () {
		
        this.element.btnSelectAllServices.click(function () {
			MyPage.element.frmSearch.find('input:checkbox').attr('checked' , true ).attr('selected' , true );
        });
        this.element.btnReset.click(function () {
			MyPage.application.resetForm();
        });
        this.element.frmSearch.submit(function () {
			var isChecked = MyPage.element.frmSearch.find('input[name="chkServiceType[]"]:checked');
			if ( ! isChecked.length)
			{
				App.alert("Please select at least one Service" , "" )
				return false;
			}
        });
		this.element.btnSearchVoluntaryOrganisation.click(function () {
			$("#hidOrganisationType").val('1');
			MyPage.element.frmSearch.submit();
		});
		this.element.btnSearchPrivateOrganisation.click(function () {
			$("#hidOrganisationType").val('2');
			MyPage.element.frmSearch.submit();
		});
		this.element.btnSearchGovernmentOrganisation.click(function () {
			$("#hidOrganisationType").val('3');
			MyPage.element.frmSearch.submit();
		});
		this.element.btnSearchAllOrganisation.click(function () {
			$("#hidOrganisationType").val('0');
			MyPage.element.frmSearch.submit();
		});

		$("#txtPostal").click(function (){
			$("#radPostal").attr("checked" , true);
		});
		$("#txtStreet").click(function (){
			$("#radStreet").attr("checked" , true);
		});
		$("#txtBlockNo").click(function (){
			$("#txtStreet").click();
		});
		$("#txtBuilding").click(function (){
			$("#radBuilding").attr("checked" , true);
		});
    },

    main: function () {
        this.prepareElement();
        this.prepareView();
        this.eventBinding();
    }
};

$(function () {
    MyPage.main();
});

/* uncomment this block if there are some conflicts with other js library/framework */
})(jQuery);

